package com.cloudwise.monitoring_system.controller;

import com.cloudwise.monitoring_system.entity.OperLog;
import com.cloudwise.monitoring_system.service.OperLogService;
import com.cloudwise.monitoring_system.util.Result;
import com.cloudwise.monitoring_system.util.ReturnStatus;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * (Operlog)表控制层
 *
 * @author makejava
 * @since 2021-06-03 11:25:00
 */
@Controller
@RequestMapping("operlog")
@ApiOperation("接口调用业务控制器")
public class OperLogController {
    /**
     * 服务对象
     */
    @Resource
    private OperLogService operlogService;


    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @ResponseBody
    @GetMapping("queryAll")
    @ApiOperation("查询所有业务接口调用情况")
    public Result queryAll(@ApiParam("业务接口调用信息") OperLog operlog) {

        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),0,
                this.operlogService.queryAll(operlog));
    }

    /**
     * 新增数据
     *
     * @param operlog 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @PostMapping("insert")
    @ApiOperation("新增一条业务接口调用数据")
    public Result insert(@ApiParam("业务接口调用信息")OperLog operlog) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.operlogService.insert(operlog));
    }

    /**
     * 查询业务接口调用情况，并且以分钟为单位记录业务接口调用次数
     * @return
     */
    @ResponseBody
    @GetMapping("queryShowChartData")
    @ApiOperation("查询业务接口调用情况，并且以分钟为单位记录业务接口调用次数")
    public Result queryShowChartData(){
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.operlogService.queryShowChartData());
    };
}
